<template>
  <div class="count">
    <h4>Count组件部分</h4>
    <h5>当前求和为:{{ sum }},十倍为{{ bigSum }}</h5>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">+</button>
    <button @click="minus">-</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import { reactive, ref, toRefs } from "vue"
import { useCountStore } from "@/store/count"
import { storeToRefs } from "pinia"
const countStore = useCountStore()

// 只暴露store中的数据，不管属性方法等
let { sum, bigSum } = storeToRefs(countStore)

let n = ref(1)
function add() {
  countStore.increment(n.value)
}
function minus() {
  countStore.decrement(n.value)

}
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
</style>